﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace weba
{
    public partial class usergengzhong : System.Web.UI.Page
    {
        protected string strOldLog = "暂无记录..";
        public string qid;
        sjklqDataContext sj = new sjklqDataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            qid = Request.QueryString["id"];
            if (!IsPostBack)
            {
                T_UserInfo ty = sj.T_UserInfo.Where(h => h.T_UserID.ToString() == qid).FirstOrDefault();
                lblAdress.Text = ty.T_Address;
                lblCity.Text = ty.T_Province;
                lblCom.Text = ty.T_CompanyName;
                lblDateTime.Text = ty.T_DateTime.ToString();
                lblMail.Text = ty.T_Email;
                lblFax.Text = ty.T_Fax;
                lblMoblie.Text = ty.T_Mobile;
                lblPerson.Text = ty.T_Person;
                LBLPost.Text = ty.T_PostCode;
                lblQQ.Text = ty.T_QQ;
                lblSex.Text = ty.T_Sex;
                lblTel.Text = ty.T_Tel;
                lblWeb.Text = ty.T_WebUrl;
                lblFrom.Text = ty.T_UserFrom.ToString();
                lblLeave.Text = ty.T_UserLeave.ToString();
                lblState.Text = ty.T_UserState.ToString();

                lblClass.Text = ty.T_UserType.ToString();
                //lblRemark.Text = string.IsNullOrEmpty(ty.T_Remark.ToString())? "empty" : ty.T_Remark.ToString();
                if (sj.T_BusinessLogInfo.Where(h => h.T_UserID == ty.T_UserID).Count() == 0)
                {
                    string svrid = (from a in sj.T_ServiceUser from b in sj.T_UserInfo where a.T_ServiceName == b.T_NowService & b.T_UserID.ToString() == qid select a).FirstOrDefault().T_ServiceID.ToString();
                    sj.addlog(int.Parse(qid), int.Parse(svrid), strOldLog);
                    sj.SubmitChanges();
                }
                else
                {
                    strOldLog = sj.T_BusinessLogInfo.Where(h => h.T_UserID == ty.T_UserID).FirstOrDefault().T_BusinessLogNote.ToString().Replace("\n", "<br/>");
                }
            }
        }

        protected void BtnSaveWorkInfo_Click(object sender, EventArgs e)
        {
            string svrid = (from a in sj.T_ServiceUser from b in sj.T_UserInfo where a.T_ServiceName == b.T_NowService & b.T_UserID.ToString() == qid select a).FirstOrDefault().T_ServiceID.ToString();
            sj.addlog(int.Parse(qid),int.Parse( svrid), txtNowWork.Value.ToString().Trim()+GetServiceState());
            sj.SubmitChanges();
            Response.Redirect(Request.RawUrl);
        }
        private string GetServiceState()
        {
            if (RBFire.Checked)
            {
                return "洽谈失败";
            }
            if (RBSuess.Checked)
            {
                return "洽谈成功";
            }
            return "0";
        }
    }
}